home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mntlb20 / lib / sleep.c < prev    next >
C/C++ Source or Header  |  1992-02-07  |  1KB  |  55 lines

  1. /* sleep -- sleep for a specified number of seconds */
  2. /* usleep -- sleep for a specified number of microSecond */
  3. /* written by Eric R. Smith and placed in the public domain */
  4.  
  5. #include <time.h>
  6. #include <mintbind.h>
  7.  
  8. /* clock() has a rez of CLOCKS_PER_SEC ticks/sec */
  9.  
  10. #define USEC_PER_TICK (1000000U / ((unsigned long)CLOCKS_PER_SEC))
  11. #define    USEC_TO_CLOCK_TICKS(us)    ((us) / USEC_PER_TICK )
  12.  
  13. void
  14. sleep(n)
  15. unsigned int    n;
  16. {
  17.     unsigned long    stop;
  18.     extern int __mint;
  19.  
  20.     if (__mint) {
  21.         while (n > 32) {
  22.             (void)Fselect(32000, 0L, 0L, 0L);
  23.             n -= 32;
  24.         }
  25.         (void)Fselect(1000*n, 0L, 0L, 0L);
  26.     }
  27.     else {
  28.         stop = clock() + n * CLOCKS_PER_SEC;
  29.         while (clock() < stop)
  30.             ;
  31.     }
  32. }
  33.  
  34. /*
  35.  * Sleep for usec microSeconds 
  36.  * the actual suspension time can be arbitrarily longer
  37.  *
  38.  */
  39. void
  40. usleep(usec)
  41.     unsigned long usec;
  42. {
  43.     unsigned long    stop;
  44.     extern int __mint;
  45.  
  46.     if (__mint) {
  47.         (void)Fselect((unsigned)(usec/1000), 0L, 0L, 0L);
  48.     }
  49.     else {
  50.         stop = clock() + USEC_TO_CLOCK_TICKS(usec);
  51.         while (clock() < stop)
  52.             ;
  53.     }
  54. }
  55.